package com.jin.webvideo.config.filter.access;

import com.jin.webvideo.base.SpringBeanGetter;
import com.jin.webvideo.base.dc.DCScript;
import com.jin.webvideo.config.filter.access.handler.AccessHandler;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@DCScript(main = "refresh", isStatic = false)
public abstract class AutoRefresher {
    protected abstract List<AccessHandler> refreshHandler();

    /**
     * final禁止重写
     */
    public final void refresh() {
        // 获取自定义的handler
        List<AccessHandler> list = refreshHandler();
        list = new ArrayList<>(list);
        // 获取必需的handler
        Map<String, AccessHandler> handlerMap = SpringBeanGetter.getBeansOfType(AccessHandler.class);
        Collection<AccessHandler> l = handlerMap.values();
        list.addAll(l);
        AccessControl.getInstance().setHandlers(list);
    }
}
